package com.ziyun.pop.web.modules.quoteFastPrintGroupPrice.controller;

import com.utility.New;
import com.utility.StringUtils;
import com.utility.http.HttpUtils;
import com.ziyun.pop.common.utils.JsonUtils;
import com.ziyun.pop.common.utils.UserUtils;
import com.ziyun.pop.modules.quoteFastPrintGroupPrice.entity.QuoteFastPrintGroupPriceEntity;
import io.renren.common.annotation.SysLog;
import io.renren.common.utils.R;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.*;


/**
 * 快印报价组合计价表
 *
 * @author llc
 * @email 
 * @date 2018-09-19 15:23:53
 */
@RestController
@RequestMapping("quoteFastPrintGroupPrice/quotefastprintgroupprice")
public class QuoteFastPrintGroupPriceController {
    @Value("${erpApi}")
    private String erpApi ;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:list")
    public R list(@RequestBody QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice){
        // 获取当前用户的商户id
        Long sellerId =  UserUtils.getCurentUser().getSellerId();
        quoteFastPrintGroupPrice.setFactoryId(sellerId.intValue());
        Map<String, Object> paramBodyMap = new HashMap<String, Object>();
        paramBodyMap.put("quoteFastPrintGroupPrice", quoteFastPrintGroupPrice);
        String url = erpApi + "/quoteFastPrintGroupPrice/quotefastprintgroupprice/list";
        String response =  HttpUtils.doPost(url,paramBodyMap);
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }
    /**
     * 信息
     *//*
    @RequestMapping("/info/{id}")
    @RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:info")
    public R info(@PathVariable("id") Integer id){
        Map<String, Object> paramBodyMap = new HashMap<String, Object>();
        paramBodyMap.put("id", id);
        String url = erpApi + "/quoteFastPrintGroupPrice/quotefastprintgroupprice/info";
        String response =  HttpUtils.doPost(url,paramBodyMap);
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }*/



    /**
     * 批量保存
     */
    @SysLog("保存组合配价")
    @RequestMapping("/save")
    public R save(@RequestBody   List<QuoteFastPrintGroupPriceEntity>  groupPriceList){
        Map<String, Object> paramBodyMap = new HashMap<String, Object>();
        paramBodyMap.put("groupPriceList", JsonUtils.object2String(groupPriceList));
        paramBodyMap.put("update_user",UserUtils.getCurentUser().getUsername());
        String url = erpApi + "/quoteFastPrintGroupPrice/quotefastprintgroupprice/save";
        String response =  HttpUtils.doPost(url,paramBodyMap);
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }


    /**
     * 删除
     */
    @SysLog("删除组合配价")
    @RequestMapping("/delete")
   /* @RequiresPermissions("quoteFastPrintGroupPrice:quotefastprintgroupprice:delete")*/
    public R delete(@RequestBody Integer[] ids){
        Map<String, Object> paramBodyMap = new HashMap<String, Object>();

        String url=erpApi+"/quoteFastPrintGroupPrice/quotefastprintgroupprice/delete";
        paramBodyMap.put("ids",JsonUtils.object2String(ids));
        paramBodyMap.put("updateName",UserUtils.getCurentUser().getUsername());
        String response =  HttpUtils.doPost(url,paramBodyMap);
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }

    /**
     * 初始化已存在的颜色和材料列表
     */
    @RequestMapping("/fastPrintMaterialList")
    public R getFastPrintMaterialList(@RequestParam Map<String, Object> params){
        // 获取当前用户的商户id
        Long sellerId =  UserUtils.getCurentUser().getSellerId();
        params.put("factory_id",sellerId);
        String url = erpApi + "/quoteFastPrintGroupPrice/quotefastprintgroupprice/fastPrintMaterialList";
        String response =  HttpUtils.doPost(url,params);
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }

      /**
     * 查找已存在的颜色和材料列表
     */
    @RequestMapping("/queryfastPrintMaterialList")
    public R queryFastPrintMaterialList(@RequestBody QuoteFastPrintGroupPriceEntity quoteFastPrintGroupPrice){
        Map<String,Object> params=new HashMap<String,Object>();
        if(StringUtils.isNotBlank(quoteFastPrintGroupPrice.getOptionName())){
            params.put("optionName",quoteFastPrintGroupPrice.getOptionName().trim());
        }
       if(StringUtils.isNotBlank(quoteFastPrintGroupPrice.getColour())){
            params.put("colour",quoteFastPrintGroupPrice.getColour().trim());
        }
        params.put("sellId",UserUtils.getCurentUser().getSellerId());
        params.put("quoteFastPrintGroupPrice",JsonUtils.object2String(quoteFastPrintGroupPrice));
        String url = erpApi + "/quoteFastPrintGroupPrice/quotefastprintgroupprice/queryfastPrintMaterialList";
        String response =  HttpUtils.doPost(url,params);
        R rs = JsonUtils.string2Object(response, R.class);
        return rs;
    }
}
